home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
3_0
/
MDEF__
/
MDEF.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-01-02
|
5KB
|
195 lines
#include "MacTypes.h"
#include "QuickDraw.h"
#include "MenuMgr.h"
#include "ToolBoxUtil.h"
#define PRECTWIDE 32 /* how wide are the patterns */
#define PRECTHIGH 32 /* how high are the patterns */
#define PATROWS 8 /* number of rows in menu */
#define PATCOLS 5 /* number of columns in menu */
#define LISTID 1000 /* Resource ID of PAT# */
/**********************************************************************
entry point for our <M>enu <DEF>inition
This menu displays patterns taken from the System PAT#.
The size of the rectangles for each pattern are designated
by PRECTWIDE and PRECTHIGH. The menu is drawn with the
rectangles, PATROWS high and PATCOLS wide, in this case,
8 patterns high by 5 patterns wide.
The MenuItem returned by the MDEF is the index within the
PAT# of the pattern chosen by the user, and can be found with...
GetIndPattern(&somePatternVariable,LISTID,MenuItem);
From the LightspeedC "Project" menu:
"Set Project Type..."
---------------------------------------
Code Resource
Type MDEF
Id 130
Name Pattern Menu [optional]
"Build Code Resource..."
"MDEF Code" if you're using the "XFER MDEF" project to
copy the MDEF and place it in the "patmenudemo.rsrc" file
**********************************************************************/
pascal void main(message,theMenu,menuRect,hitPt,whichItem)
int message;
MenuHandle theMenu;
Rect *menuRect;
Point hitPt;
int *whichItem;
{
/*
what does the menu manager want us to do?
*/
switch(message){
case mDrawMsg: /*
draw the menu
*/
domenudraw(theMenu,menuRect);
break;
case mChooseMsg: /*
user is choosing a menu item
*/
domenuchoose(theMenu,menuRect,hitPt,whichItem);
break;
case mSizeMsg: /*
tell the menu manager how large the menu
is when it is dropped down from the
menubar by filling in the menuHeight and
menuWidth fields of the MenuHandle data
*/
domenusize(theMenu);
break;
default: break;
}
}
calcitemrect(MenuRect,resultRect,item)
Rect *MenuRect,*resultRect;
int item;
{
int row,col;
/*
calculate the rectangle within the menu, (therefore, within MenuRect),
for any given menu item designated by "item". Find out which row and
column the item is in, then construct the rectangle, and return the
rectangle as the function result
*/
row = (item-1) / PATCOLS;
col = (item-1) % PATCOLS;
resultRect->left = MenuRect->left + col * PRECTWIDE;
resultRect->top = MenuRect->top + row * PRECTHIGH;
resultRect->right = resultRect->left + PRECTWIDE;
resultRect->bottom = resultRect->top + PRECTHIGH;
}
domenudraw(theMenu,menuRect)
MenuHandle theMenu;
Rect *menuRect;
{
Rect itemRect;
Pattern thePat;
int index;
/*
cycle through PATROWS * PATCOLS items, getting a pattern from the
System PAT#, and filling the menu rectangles with that pattern
*/
for (index = 1; index <= (PATROWS * PATCOLS); index++){
/* get the pattern */
GetIndPattern(&thePat,LISTID,index);
/* calculate the rectangle in the menu */
calcitemrect(menuRect,&itemRect,index);
/* draw the menu item */
InsetRect(&itemRect,1,1);
FillRect(&itemRect,thePat);
FrameRect(&itemRect);
}
}
domenuchoose(theMenu,menuRect,hitPt,whichItem)
MenuHandle theMenu;
Rect *menuRect;
Point hitPt;
int *whichItem;
{
int index,itemChosen;
Rect testRect,oldRect;
itemChosen = 1000;
/*
an impossible menu choice
*/
/*
find out which menu item rectangle the mouse is in
*/
for (index=1; index<=(PATROWS*PATCOLS); index++){
calcitemrect(menuRect,&testRect,index);
if (PtInRect(hitPt,&testRect)){
/*
the mouse is in the "indexth" menu item
*/
itemChosen = index;
break;
}
}
if (itemChosen != 1000){
/*
then we found the mouse in a menu item.
was there an old menu item selected?
*/
if ((*whichItem != 0) && (*whichItem != itemChosen)){
/*
if so, then un-select it
*/
calcitemrect(menuRect,&oldRect,*whichItem);
PenMode(patXor);
FrameRect(&oldRect);
}
/*
tell the menu manager which item was last selected
*/
*whichItem = itemChosen;
/*
and select it
*/
calcitemrect(menuRect,&oldRect,itemChosen);
PenMode(patCopy);
FrameRect(&oldRect);
}
else{
/*
no menu item was selected, so un-select any previous
menu item selected
*/
if (!PtInRect(hitPt,menuRect)){
calcitemrect(menuRect,&oldRect,*whichItem);
PenMode(patXor);
FrameRect(&oldRect);
*whichItem = 0;
}
}
}
domenusize(theMenu)
MenuHandle theMenu;
{
/*
tell the menu manager how large the menu rectangle is
*/
(**theMenu).menuWidth = PATCOLS*PRECTWIDE;
(**theMenu).menuHeight = PATROWS*PRECTHIGH;
}